package com.jinjie.config.tomcat;

import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: com.jinjie.config.tomcat
 * @Description: 多端口启用
 * @author: Administrator
 * @create: 2025-01-21 10:03
 **/
@Slf4j
//@Configuration
public class MultiplePortConfiguration {
    @Bean
    public TomcatServletWebServerFactory servletWebServerFactory(){
        log.info("================= 开始配置tomcat");
        TomcatServletWebServerFactory tomcatServletWebServerFactory = new TomcatServletWebServerFactory();
        //tomcatServletWebServerFactory.addAdditionalTomcatConnectors(createStandardConnector(8080));
        tomcatServletWebServerFactory.addConnectorCustomizers(connector -> connector.setProperty("server", ""));
        return tomcatServletWebServerFactory;
    }

    private Connector createStandardConnector(Integer port){
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setPort(port);
        return connector;
    }

}
